#define _CRT_SECURE_NO_WARNINGS 1





//https://www.luogu.com.cn/problem/P1049





#include<iostream>
using namespace std;
const int N = 20010;
int n, m;
int dp[N];
int main()
{
	cin >> m >> n;
	for (int i = 1;i <= n;i++)
	{
		int v;
		cin >> v;
		for (int j = m;j >= v;j--)
			dp[j] = max(dp[j], dp[j - v] + v);
	}
	cout << m - dp[m];
	return 0;
}









